package com.lb.jwitter.action;


import java.util.ArrayList; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.List; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXALopMonHocHocVien;
import com.lb.jwitter.service.TblQLDTTXALopMonHocHocVienService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXALopMonHoctblQLDTTXALopMonHocHocVienSearchAction{
    private int pageSize; 
    public void setPageSize(int pageSize) {
       this.pageSize = pageSize;
     }

    public int getPageSize() {
       return pageSize;
 }

    private int page; 
    public void setPage(int page) { this.page = page;   }

    public int getPage() {
       return page;
   }

    private int pages; 
    public void setPages(int pages) { this.pages = pages;   }

    public int getPages() {
       return pages;
     }

    private String dataString; 
    public void setDataString(String dataString) { this.dataString = dataString;    }

    public String getDataString() {
       return dataString;
    }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id ;
   }
    public void setId(int id) {
       this.id = id;
    }

    private int hocVienId; 
    public void setHocVienId(int hocVienId) {
       this.hocVienId = hocVienId;
  }

    public int getHocVienId() {
       return hocVienId;
  }

    private int lopMonHocId; 
    public void setLopMonHocId(int lopMonHocId) {
       this.lopMonHocId = lopMonHocId;
  }

    public int getLopMonHocId() {
       return lopMonHocId;
  }

    private double diemCK; 
    public void setDiemCK(double diemCK) {
       this.diemCK = diemCK;
   }

    public double getDiemCK() {
       return diemCK;
   }

    private double diemGK; 
    public void setDiemGK(double diemGK) {
       this.diemGK = diemGK;
   }

    public double getDiemGK() {
       return diemGK;
   }

    private double diemTH; 
    public void setDiemTH(double diemTH) {
       this.diemTH = diemTH;
   }

    public double getDiemTH() {
       return diemTH;
   }

    private double tongdiem; 
    public void setTongdiem(double tongdiem) {
       this.tongdiem = tongdiem;
   }

    public double getTongdiem() {
       return tongdiem;
   }

    private int trangThai; 
    public void setTrangThai(int trangThai) {
       this.trangThai = trangThai;
  }

    public int getTrangThai() {
       return trangThai;
  }

    private List<TblQLDTTXALopMonHocHocVien> tblQLDTTXALopMonHocHocViens; 
    public List<TblQLDTTXALopMonHocHocVien>  getTblQLDTTXALopMonHocHocViens() {
        return tblQLDTTXALopMonHocHocViens; 
      } 

    private TblQLDTTXALopMonHocHocVienService tblQLDTTXALopMonHocHocVienService; 

	private int preSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_LopMonHoc_HocVien", "xem")){ 
        return "noprivilege"; 
    }        tblQLDTTXALopMonHocHocVienService = (TblQLDTTXALopMonHocHocVienService) context.getBean("tbl_QLDTTXA_LopMonHoc_HocVienClient"); 
        msg = new Message(); 
        List<ConditionReport> cons = new ArrayList<ConditionReport>(); 

    if(hocVienId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("hocVienId.id");
        con.setValue1(new Long(hocVienId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(lopMonHocId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("lopMonHocId.id");
        con.setValue1(new Long(lopMonHocId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(diemCK != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("diemCK");
        con.setValue1(diemCK);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(diemGK != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("diemGK");
        con.setValue1(diemGK);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(diemTH != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("diemTH");
        con.setValue1(diemTH);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(tongdiem != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("tongdiem");
        con.setValue1(tongdiem);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(trangThai != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("trangThai");
        con.setValue1(trangThai);
        con.setOperator("eq");
        cons.add(con);	
    } 
        preSearch(msg, cons); 
       if (msg.isPreMessage_b()) 
       { 
           if(pageSize == 0){ 
               pageSize = 20; 
           } 
            if(page == 0){ 
               page =1; 
           } 
           tblQLDTTXALopMonHocHocViens = tblQLDTTXALopMonHocHocVienService.findtblQLDTTXALopMonHocHocVienByCondition(cons,0,0);//pageSize,page); 
           pages = tblQLDTTXALopMonHocHocVienService.counttblQLDTTXALopMonHocHocVienByCondition(cons)/pageSize + 1; 
           postSearch(msg, cons); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
      dataString = ""; 
      dataString += "&id=" + id; 
      dataString += "&hocVienId=" + hocVienId; 
      dataString += "&lopMonHocId=" + lopMonHocId; 
      dataString += "&diemCK=" + diemCK; 
      dataString += "&diemGK=" + diemGK; 
      dataString += "&diemTH=" + diemTH; 
      dataString += "&tongdiem=" + tongdiem; 
      dataString += "&trangThai=" + trangThai; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Seach tbl_QLDTTXA_LopMonHoc_HocVien Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
